package test.multithread;

public class Tikets {

	public static void main(String[] args) {

		Sell s = new Sell();

		Thread th = new Thread(s);
		th.start();
		Thread th2 = new Sell1();
		th2.start();
		System.out.println("Main out!");

	}

}

class Sell implements Runnable {

	static int i;
	static Object obj=new Object();
	public void run() {
		synchronized (this) {
			while (i++ < 100) {
				try {
					Thread.sleep(1);
					//wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName()
						+ " is Running" + i);

			}
		}

	}

}

class Sell1 extends Thread {
	
	public void run() {
		Class c=null;
		try {
			c = Class.forName("test.multithread.Sell");
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		synchronized (c) {
			while (Sell.i++ < 100) {
				try {
					Thread.sleep(1);
					//	wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName()
						+ " is Running" + Sell.i);

			}
		}
		
	}

}
